<template>
	<div class="main">
		<div class="panel">
			<div class="panel-body">
				<form>
					<div class="form-group form-material floating" data-plugin="formMaterial">
						<input type="username" class="form-control" name="username" v-model="userName" :class="{ empty: !userName }" />
						<label class="floating-label">账号</label>
					</div>
					<div class="form-group form-material floating" data-plugin="formMaterial">
						<input type="password" class="form-control" name="password" v-model="password" :class="{ empty: !password }" />
						<label class="floating-label">密码</label>
					</div>
					<div class="form-group flex flex-pack-justify">
						<a-checkbox v-model="rememberMe">记住密码</a-checkbox>
						<!-- <a class="float-right" href="forgot-password.html">Forgot password?</a> -->
					</div>
					<a-button size="large" type="primary" class="login-button" :loading="loginBtn" :disabled="loginBtn" @click="handleSubmit">登录</a-button>
				</form>
			</div>
		</div>
	</div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
	data() {
		return {
			loginBtn: false,
			rememberMe: true,
			userName: '',
			password: ''
		};
	},
	mounted() {
		this.$nextTick(() => {
			try {
				const loginInfo = JSON.parse(localStorage.getItem('loginInfo'));
				this.userName = loginInfo.userName;
				this.password = loginInfo.password;
			} catch (e) {
				// TODO handle the exception
			}
		});
	},
	methods: {
		...mapActions(['Login', 'Logout']),
		handleSubmit(e) {
			e.preventDefault();
			this.loginBtn = true;
			if (this.userName && this.password) {
				const loginParams = {
					userName: this.userName.trim(),
					password: this.password.trim()
				};
				this.$postAction(this.$api.adminLogin, loginParams)
					.then(da => {
						console.log('da', da);
						if (da.code == 200) {
							localStorage.setItem('token', da.data);
							/* TODO 是否记住密码 */
							if (this.rememberMe) {
								localStorage.setItem('loginInfo', JSON.stringify(loginParams));
							} else {
								/* 忘记密码 */
								localStorage.removeItem('loginInfo');
							}
							this.$router.push({
								path: '/system'
							});
						}
					})
					.finally(() => {
						this.loginBtn = false;
					});
			} else {
				setTimeout(() => {
					this.loginBtn = false;
				}, 600);
			}
		}
		
	}
};
</script>

<style lang="less" scoped>
.panel {
	width: 400px;
	margin-bottom: 45px;
	background: #fff;
	border-radius: 0.286rem;
}

.panel .panel-body {
	padding: 50px 40px 40px;
}

.panel .brand-text {
	margin-top: 8px;
	font-size: 18px;
	text-align: center;
	font-family: Roboto, sans-serif;
	line-height: 1.2;
	color: #37474f;
}
.form-control {
	display: block;
	width: 100%;
	padding: 0.429rem 1rem;
	font-size: 1rem;
	line-height: 1.57142857;
	color: #76838f;
	background-color: #fff;
	background-image: none;
	background-clip: padding-box;
	border: 1px solid #e4eaec;
	border-radius: 0.215rem;
	box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%);
	transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
	box-sizing: border-box;
	height: 2.573rem;
	font-weight: 100;
}
.form-material {
	position: relative;
}

.form-material.floating {
	margin-top: 20px;
	margin-bottom: 20px;
}

.form-material.floating + .form-material.floating {
	margin-top: 40px;
}
.form-material .form-control ~ .floating-label {
	top: 0.57142857rem;
	font-size: 1rem;
}
.form-material .form-control {
	padding-right: 0;
	padding-left: 0;
	background-color: transparent;
	background-color: transparent;
	background-repeat: no-repeat;
	background-position: center bottom, center calc(100% - 1px);
	background-size: 0 2px, 100% 1px;
	transition: background 0s ease-out;
}

.form-material .form-control,
.form-material .form-control.focus,
.form-material .form-control:focus {
	float: none;
	background-image: linear-gradient(#3e8ef7, #3e8ef7), linear-gradient(#e4eaec, #e4eaec) !important;
	border: 0;
	border-radius: 0;
	box-shadow: none;
}
// .form-material .form-control:-webkit-autofill {
// 	-webkit-box-shadow: 0 0 0 1000px white inset !important;
// }
.no-cssgradients .form-material .form-control {
	border-bottom: 2px solid #e4eaec;
}

.form-material .form-control::-webkit-input-placeholder {
	color: #a3afb7;
}

.form-material .form-control::-moz-placeholder {
	color: #a3afb7;
}

.form-material .form-control:-ms-input-placeholder {
	color: #a3afb7;
}

.form-material .form-control:disabled::-webkit-input-placeholder {
	color: #ccd5db;
}

.form-material .form-control:disabled::-moz-placeholder {
	color: #ccd5db;
}

.form-material .form-control:disabled:-ms-input-placeholder {
	color: #ccd5db;
}

.form-material .form-control.focus,
.form-material .form-control:focus {
	background-size: 100% 2px, 100% 1px;
	outline: 0;
	transition-duration: 0.3s;
}

.no-cssgradients .form-material .form-control.focus,
.no-cssgradients .form-material .form-control:focus {
	background: 0 0;
	border-bottom: 2px solid #3e8ef7;
}

.form-material .form-control:disabled,
.form-material .form-control[disabled],
fieldset[disabled] .form-material .form-control {
	background: 0 0;
	background: 0 0;
	border-bottom: 1px dashed #ccd5db;
}

.form-material .form-control:disabled ~ .floating-label,
.form-material .form-control[disabled] ~ .floating-label,
fieldset[disabled] .form-material .form-control ~ .floating-label {
	color: #ccd5db;
}

.form-material select[multiple],
.form-material select[size],
.form-material textarea.form-control {
	height: auto;
}

.form-material .form-control-label {
	font-weight: 500;
}

.form-material.form-group .form-control-label {
	padding-top: 0;
	padding-bottom: 0;
}

.form-material .floating-label {
	position: absolute;
	left: 0;
	font-size: 1rem;
	color: #76838f;
	pointer-events: none;
	transition: 0.3s ease all;
}

.form-material .floating-label.floating-label-static {
	position: relative;
	top: auto;
	display: block;
}

.form-material [class*='col-'] > .floating-label {
	left: 1.0715rem;
}

.form-material .form-control ~ .floating-label {
	top: 0.57142857rem;
	font-size: 1rem;
}

.form-material .form-control.focus ~ .floating-label,
.form-material .form-control:focus ~ .floating-label,
.form-material .form-control:not(.empty) ~ .floating-label {
	top: -0.8rem;
	font-size: 0.8rem;
}

.form-material .form-control:-webkit-autofill ~ .floating-label {
	top: -0.8rem;
	font-size: 0.8rem;
}

.form-material .form-control-sm ~ .floating-label {
	top: 0.429rem;
	font-size: 0.858rem;
}

.form-material .form-control-sm.focus ~ .floating-label,
.form-material .form-control-sm:focus ~ .floating-label,
.form-material .form-control-sm:not(.empty) ~ .floating-label {
	top: -0.6864rem;
	font-size: 0.6864rem;
}

.form-material .form-control-sm:-webkit-autofill ~ .floating-label {
	top: -0.6864rem;
	font-size: 0.6864rem;
}

.form-material .form-control-lg ~ .floating-label {
	top: 0.4286666667rem;
	font-size: 1.286rem;
}

.form-material .form-control-lg.focus ~ .floating-label,
.form-material .form-control-lg:focus ~ .floating-label,
.form-material .form-control-lg:not(.empty) ~ .floating-label {
	top: -1.0288rem;
	font-size: 1.0288rem;
}

.form-material .form-control-lg:-webkit-autofill ~ .floating-label {
	top: -1.0288rem;
	font-size: 1.0288rem;
}

.form-material .form-control.focus ~ .floating-label,
.form-material .form-control:focus ~ .floating-label,
.form-material .form-control:not(.empty) ~ .floating-label {
	font-weight: 500;
}

.form-material .form-control:-webkit-autofill ~ .floating-label {
	font-weight: 500;
}

.form-material .form-control.focus ~ .floating-label,
.form-material .form-control:focus ~ .floating-label {
	color: #3e8ef7;
}

.form-material textarea.form-control {
	padding-bottom: 0.429rem;
	resize: none;
}

.form-material.floating textarea.form-control {
	padding-top: 0.429rem;
}

.form-material select.form-control {
	border: 0;
	border-radius: 0;
}

.form-material:not(.floating) .form-control-label + select[multiple] {
	margin-top: 5px;
}

.form-material .hint {
	position: absolute;
	display: none;
	font-size: 80%;
}

.form-material .form-control.focus ~ .hint,
.form-material .form-control:focus ~ .hint {
	display: block;
}

.form-material .form-control.focus:invalid ~ .floating-label,
.form-material .form-control:not(.empty):invalid ~ .floating-label {
	color: #ff4c52;
}

.form-material .form-control:invalid {
	background-image: linear-gradient(#ff4c52, #ff4c52), linear-gradient(#e4eaec, #e4eaec);
}

.form-material.has-warning .form-control.focus,
.form-material.has-warning .form-control:focus,
.form-material.has-warning .form-control:not(.empty) {
	background-image: linear-gradient(#eb6709, #eb6709), linear-gradient(#e4eaec, #e4eaec);
}
@media (max-width: 479px) {
	.page-content {
		padding: 30px 20px;
	}

	.panel {
		width: auto;
		padding: 10px;
	}

	.panel-body {
		padding: 35px 25px;
	}
}
button.login-button {
	padding: 0 15px;
	font-size: 18px;
	height: 46px;
	width: 100%;
	border-radius: 4px;
	background: #247cf0;
	margin-top: 40px;
}
button.login-button.focus,
button.login-button.hover,
button.login-button:focus,
button.login-button:hover {
	color: #fff;
	background-color: #589ffc;
	border-color: #589ffc;
	box-shadow: none;
}
.user-layout-login {
	label {
		font-size: 14px;
	}

	.getCaptcha {
		display: block;
		width: 100%;
		height: 40px;
	}

	.forge-password {
		font-size: 14px;
	}

	/deep/ .ant-input {
		border: none;
		border-bottom: 1px solid #d9d9d9;
	}
	/deep/ .ant-input:focus {
		border-color: #40a9ff;
		border-right-width: 1px !important;
		outline: 0;
		box-shadow: none;
	}
	/deep/ .has-error .ant-input:focus {
		border-color: #ff4d4f;
		border-right-width: 1px !important;
		outline: 0;
		box-shadow: none;
	}

	.user-login-other {
		text-align: left;
		margin-top: 24px;
		line-height: 22px;

		.item-icon {
			font-size: 24px;
			color: rgba(0, 0, 0, 0.2);
			margin-left: 16px;
			vertical-align: middle;
			cursor: pointer;
			transition: color 0.3s;

			&:hover {
				color: #1890ff;
			}
		}

		.register {
			float: right;
		}
	}
}
</style>
